Skip to content

Remove ecdsa dependency, use cryptography only#2

Closed
prusnak wants to merge 1 commit intomasterfrom
remove-ecda
Closed

Remove ecdsa dependency, use cryptography only#2
prusnak wants to merge 1 commit intomasterfrom
remove-ecda

Conversation

@prusnak
Copy link
Copy Markdown
Member

@prusnak prusnak commented Oct 28, 2025

What title says

The code was generated using Codex - please review meticulously!

The tests pass though.

Comment thread slip10/utils.py
if x1 == x2:
return None

slope = ((y2 - y1) * self._inverse_mod((x2 - x1) % self.p)) % self.p
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

% is unnecessary since it happens in _inverse_mod().

Suggested change
slope = ((y2 - y1) * self._inverse_mod((x2 - x1) % self.p)) % self.p
slope = ((y2 - y1) * self._inverse_mod(x2 - x1)) % self.p

Comment thread slip10/utils.py
if y == 0:
return None

slope = ((3 * x * x + self.a) * self._inverse_mod((2 * y) % self.p)) % self.p
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
slope = ((3 * x * x + self.a) * self._inverse_mod((2 * y) % self.p)) % self.p
slope = ((3 * x * x + self.a) * self._inverse_mod(2 * y)) % self.p

Comment thread slip10/utils.py
y3 = (slope * (x - x3) - y) % self.p
return x3, y3

def _scalar_mult(self, scalar: int, point: Tuple[int, int]) -> Point:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def _scalar_mult(self, scalar: int, point: Tuple[int, int]) -> Point:
def _scalar_mult(self, scalar: int, point: Point) -> Point:

Comment thread slip10/utils.py
Comment on lines +205 to +206
x = int.from_bytes(data[1 : 1 + self.coordinate_size], "big")
y = int.from_bytes(data[1 + self.coordinate_size :], "big")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
x = int.from_bytes(data[1 : 1 + self.coordinate_size], "big")
y = int.from_bytes(data[1 + self.coordinate_size :], "big")
x = int.from_bytes(data[1 : 1 + self.coordinate_size], "big")
if (x >= self.p):
raise ValueError("Invalid x-coordinate")
y = int.from_bytes(data[1 + self.coordinate_size :], "big")
if (y >= self.p):
raise ValueError("Invalid y-coordinate")

Comment thread slip10/utils.py
if len(data) != self.coordinate_size + 1 or data[0] not in (2, 3):
raise ValueError("Invalid public key encoding")

x = int.from_bytes(data[1:], "big")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
x = int.from_bytes(data[1:], "big")
if (x >= self.p):
raise ValueError("Invalid x-coordinate")

Comment thread slip10/utils.py
Comment on lines +228 to +229
if x >= self.p:
raise ValueError("Invalid point")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if x >= self.p:
raise ValueError("Invalid point")
if self.p % 4 != 3:
raise NotImplementedError("Square root for this modulus is not implemented")

@andrewkozlik
Copy link
Copy Markdown
Collaborator

Closing in favor of #4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants